﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Bootstrap
{
    /*
     * Evaluate condition of a whole list of shapes,
     * usefull for tripel and quad zones, lists, etc...
     */
    public static class ShapeEvaluator {
        private static readonly Func<string, int, string> toClass = (p, c) => c > 0 ? p + "-" + c : "";

        public static string Classify(dynamic model, string prefix, params string[] shapes) {
            Func<dynamic, bool> c = x => x != null;
            int notNullCount = Count(model, c, shapes);
            return toClass(prefix, notNullCount);
        }
        
        public static int Count(dynamic model, Func<dynamic, bool> condition, params string[] shapes) {
            return shapes.Count(x => condition(model[x]));
        }

        public static int NotNull(dynamic model, params string[] shapes) {
            Func<dynamic, bool> c = x => x != null;
            return Count(model, c, shapes);
        }
    }

    
}
